
<template>
  <div style="height: 100%">
    <el-container style="height: 100%;">
    <el-aside :width="asideWidth+'px'" style="background-color: rgb(238, 241, 246);height: 100%;">
      <el-menu :default-openeds="['1', '3']" style="height: 100%;" :collapse = "isCollapsed" :collapse-transition = "false">
        <div style="height: 60px; line-height: 60px; text-align: center;">
          <img src="@/assets/css/3.png" alt="" style="width: 40px;position: relative;top: 10px; margin-right: 2px">
          <b>教职工信息管理系统</b>
        </div>
        <el-submenu index="1">
          <template slot="title"><i class="el-icon-message"></i>
           <span>导航一</span>
          </template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="1-1">选项1</el-menu-item>
            <el-menu-item index="1-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="1-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title"><i class="el-icon-menu"></i>导航二</template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="2-1">选项1</el-menu-item>
            <el-menu-item index="2-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="2-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="2-4">
            <template slot="title">选项4</template>
            <el-menu-item index="2-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title"><i class="el-icon-setting"></i>导航三</template>
          <el-menu-item-group>
            <template slot="title">分组一</template>
            <el-menu-item index="3-1">选项1</el-menu-item>
            <el-menu-item index="3-2">选项2</el-menu-item>
          </el-menu-item-group>
          <el-menu-item-group title="分组2">
            <el-menu-item index="3-3">选项3</el-menu-item>
          </el-menu-item-group>
          <el-submenu index="3-4">
            <template slot="title">选项4</template>
            <el-menu-item index="3-4-1">选项4-1</el-menu-item>
          </el-submenu>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="font-size: 12px; border-bottom: 1px ;background-color: white; line-height: 60px;display:flex;">
        <div style="flex: 1; font-size: 18px">
          <span :class="CollapseBtnClass" style="cursor: pointer" @click="collapse"></span>
        </div>
        <el-dropdown style="width: 50px">
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>查看</el-dropdown-item>
            <el-dropdown-item>新增</el-dropdown-item>
            <el-dropdown-item>删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>王小虎</span>
      </el-header>

      <el-main>
        <div style="padding: 10px 0">
          <el-input style="width: 200px" placeholder="请输入工号" suffix-icon="el-icon-search" v-model="username" class="ml-5"></el-input>
          <el-input style="width: 200px" placeholder="请输入姓名" suffix-icon="el-icon-message" v-model="name" class="ml-5"></el-input>
          <el-input style="width: 200px" placeholder="请输入科室" suffix-icon="el-icon-position" v-model="department" class="ml-5"></el-input>
          <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
          <el-button  type="danger" @click="reset">重置</el-button>
        </div>

        <div style="margin: 10px 0">
          <el-button type="primary" @click="handleAdd">新增<i class="el-icon-circle-plus-outline"></i></el-button>
          <el-button type="primary">导入<i class="el-icon-bottom"></i></el-button>
          <el-button type="primary">导出<i class="el-icon-top"></i></el-button>
        </div>

        <div style="margin: 10px 0">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>活动管理</el-breadcrumb-item>
            <el-breadcrumb-item>活动列表</el-breadcrumb-item>
            <el-breadcrumb-item>活动详情</el-breadcrumb-item>
          </el-breadcrumb>
        </div>


        <el-table :data="tableData">
          <el-table-column
              type="selection"
              width="55"  @selection-change="handleSelectionChange">
          </el-table-column>
          <el-table-column prop="id" v-model="form.id" label="ID" width="80"></el-table-column>
          <el-table-column prop="username" v-model="form.username" label="工号" width="100"></el-table-column>
          <el-table-column prop="name" v-model="form.name" label="姓名" width="100"></el-table-column>
          <el-table-column prop="address" v-model="form.address" label="科室" width="100"></el-table-column>
          <el-table-column prop="department" v-model="form.department" label="职位" width="100"></el-table-column>
          <el-table-column prop="sex" v-model="form.sex" label="性别" width="100"></el-table-column>
          <el-table-column prop="avatar" v-model="form.avatar" label="头像" width="100"></el-table-column>
          <el-table-column prop="salary" v-model="form.salary" label="薪资" width="100"></el-table-column>
          <el-table-column prop="phone" v-model="form.phone" label="手机号码" width="100"></el-table-column>
          <el-table-column prop="idnumber" v-model="form.idnumber" label="身份证" width="100"></el-table-column>
          <el-table-column prop="email" v-model="form.email" label="邮箱" width="100"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="success" @click="handleEdit(scope.row)">
                编辑
                <i class="el-icon-edit"></i></el-button>
              <el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='我再想想' icon="el-icon-info"  icon-color="red" title="您确定要删除吗？" @confirm="del(scope.row.id)">


              <el-button type="danger" slot="reference">删除<i class="el-icon-remove-outline"></i></el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <div style="     padding: 10px 0">
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
        <el-dialog title="教职工信息" :visible.sync="dialogFormVisible" width="30%">
          <el-form label-width="100px" size="small">
            <el-form-item label="ID">
              <el-input v-model="form.id" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="工号">
              <el-input v-model="form.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="姓名">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="科室">
              <el-input v-model="form.address" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="职位">
              <el-input v-model="form.department" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="性别">
              <el-input v-model="form.sex" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="头像">
              <el-input v-model="form.avatar" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="薪资">
              <el-input v-model="form.salary" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="手机号码">
              <el-input v-model="form.phone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="身份证">
              <el-input v-model="form.idnumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input v-model="form.email" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="save">确 定</el-button>
          </div>
        </el-dialog>
      </el-main>
    </el-container>
    </el-container>
  </div>
</template>

<style>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>

<script>
import {Collapse} from "element-ui";
import request from "@/utils/request";

export default {
  name: "HomeView.vue",
  computed: {
    Collapse() {
      return Collapse
    }
  },
  data() {
    return {
      tableData: [],
      total:0,
      pageNum:1,
      pageSize:10,
      username:"",
      id:1,
      name:"",
      sex:"",
      salary:"",
      avatar:"",
      phone:"",
      idnumber:"",
      address:"",
      email:"",
      form:{},
      department:"",
      dialogFormVisible: false,
      CollapseBtnClass:'el-icon-s-fold',
      isCollapsed:false,
      asideWidth:200,
      multipleSelection:[]
    }
  },
  created() {
    this.load()
  },
  methods:{
    collapse(){
      this.isCollapsed = !this.isCollapsed
      if(this.isCollapsed){
        this.asideWidth = 0
        this.CollapseBtnClass = 'el-icon-s-unfold'
      } else {
        this.asideWidth=200
        this.CollapseBtnClass = 'el-icon-s-fold'
      }
    },
    load(){
      request.get("/user/selectPage",{
        params:{
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          username: this.username,
          name:this.name,
          department:this.department
        }
      }).then(res=>{
        console.log(res)
        this.tableData = res.data.list;
        this.total = res.data.total;
      })
    },
    save(){
      request.post("/user/add",this.form).then(res=>{
        if(res){
          this.$message.success("保存成功")
          this.dialogFormVisible =false
        }else{
          this.$message.success("error!")
        }
      })
    },
    handleAdd(){
      this.dialogFormVisible = true
      this.form={}
    },
    handleEdit(row){
      this.form = row
      this.dialogFormVisible = true
    },
    del(id){
      request.delete("/user/delete/"+id).then(res=>{
        if(res){
          this.$message.success("删除成功")
        }else{
          this.$message.success("error!")
        }
      })
    },
    handleSelectionChange(val){
      this.multipleSelection=val
      console.log(val)
    },
    reset(){
      this.username=""
      this.name=""
      this.department=""
      this.load()
    },
    handleSizeChange(pageSize){
      console.log(pageSize)
      this.pageSize = pageSize
      this.load();
    },
    handleCurrentChange(pageNum){
      console.log(pageNum)
      this.pageNum = pageNum;
      this.load();
    }
  }
};
</script>



